﻿using System.Web.Mvc;
using JoelAbrahamsson.BlogExtensions;

namespace JoelAbrahamsson.Web.ModelBinders
{
    public class EntryModelBinder : IModelBinder
    {
        private ExtendedBlogHandlerFacade BlogHandlerFacade { get; set; }

        public EntryModelBinder(ExtendedBlogHandlerFacade blogHandlerFacade)
        {
            BlogHandlerFacade = blogHandlerFacade;
        }

        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            return BlogHandlerFacade.GetEntryBySlug(controllerContext.RouteData.Values["slug"].ToString());
        }
    }
}
